"""
题目要求：
一个有序数列（含多个相同值），找出类似目标值的起始下标和末尾下标。例如：数列[1, 2, 3, 3, 4, 4, 5, 5, 5, 6, 7, 8, 8]，输入5，用二分法输出5的起始下标和末尾下标。
"""

def searchRange(nums, target):
    if len(nums) == 0:
        return "not found"
    elif target < nums[0] or target > nums[-1]:
        return "not found"
    else:
        l, r = 0, len(nums) - 1
        while l <= r:
            mid = (l + r) // 2
            if target > nums[mid]:
                l = mid + 1
            elif __1__:
                r = mid - 1
            elif target == nums[mid]:
                __2__
                while l - 1 >= 0 and nums[l - 1] == target:
                    l -= 1
                while r + 1 <= len(nums) - 1 and nums[r + 1] == target:
                    r += 1
                return [l, r]
    return "not found"
nums = [1, 2, 3, 3, 4, 4, 5, 5, 5, 6, 7, 8, 8]
a = searchRange(nums, 5)
print(a)